import { ServiceBase } from '@jctech/api/ServiceBase';
import { ApiPre } from '../../config';

const urlbase = `${ApiPre}/Area`;

export class AreaService extends ServiceBase {
  GetCountry() {
    return this.request<CountryEm[]>(`${urlbase}/GetCountry`, null);
  }

  getProvince() {
    return this.request<JcProvince[]>(`${urlbase}/GetProvince`, null);
  }

  getCity(provinceCode: string) {
    return this.request<JcCity[]>(`${urlbase}/GetCity`, {
      provinceCode
    });
  }

  getArea(cityCode: string) {
    return this.request<JcArea[]>(`${urlbase}/GetArea`, {
      cityCode
    });
  }

  getTown(areaCode: string) {
    return this.request<JcTown[]>(`${urlbase}/GetTown`, {
      areaCode
    });
  }

  getVillage(townCode: string) {
    return this.request<JcVillage[]>(`${urlbase}/GetVillage`, {
      townCode
    });
  }

  getAreaFullName(areacode: string) {
    return this.request<string>(`${urlbase}/GetAreaFullName`, {
      areacode
    });
  }

  GetAreaInfo(areaCode: string) {
    return this.request<AddressDetail>(`${urlbase}/GetAreaInfo`, { areaCode });
  }

  GetPlaceCodeAndDetailName(address: string) {
    return this.request<AddressCodeAndDetail>(`${urlbase}/GetPlaceCodeAndDetailName`, { address });
  }
}

export class JcCountry {
  CountryID = 0;
  CountryNameCN = '';
  CountryNameEN = '';
}

export class JcProvince {
  ProvinceCode = '';
  ProvinceName = '';
  CustomCode?: string = '';
}

export class JcCity {
  CityCode = '';
  CityName = '';
  CustomCode?: string = '';
  bNew?: string = '';
}

export class JcArea {
  AreaCode = '';
  AreaName = '';
  CustomCode?: string = '';
  bNew?: string = '';
}

export class JcTown {
  TownCode = '';
  TownName = '';
}

export class JcVillage {
  VillageCode = '';
  VillageName = '';
}

export class CountryEm {
  CountryID = 0;
  CountryNameCN = '';
  CountryNameEN = '';
}

export class AddressCodeAndDetail {
  Code = '';
  DetailAddress = '';
}

export class AddressDetail {
  ProvinceEm: JcProvince = new JcProvince();
  CityEm: JcCity = new JcCity();
  AreaEm: JcArea = new JcArea();
  TownEm: JcTown = new JcTown();
  VillageEm: JcVillage = new JcVillage();
  FullAddressString = '';
}
